<?php
class PostsModel extends Model
{
	var $attachList;
	
	var $_validate = array(
		array('post_title','require','标题必须！',MUST_TO_VALIDATE),
		array('post_content','require','内容必须！',MUST_TO_VALIDATE)
	);

	var $_auto = array(
		array('post_author','getAuthor' ,'ADD','callback'),
		array('post_date','now' ,'ADD','callback'),
		array('post_modified','now','ALL','callback'),
		array('comment_count','0','ADD')
	);
	
	// 与附件表相关联,每篇日志有多个附件
	var $_link = array(
		array('mapping_type'=>HAS_MANY,
			'class_name'=>'Attach',
			'foreign_key'=>'`postId`',
			'mapping_name'=>'attachList')
	);

	function getAuthor()
	{
		return Session::get(C('USER_AUTH_KEY'));
	}

	function now()
	{
		return date("Y-m-d H:i:s");
	}
}
?>